"use strict";
cc._RF.push(module, 'a0abdogcjZOMZzgTaOzof6T', 'MixMgr');
// scripts/MixMgr.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("DataMgr"),
    i = e("VideoHint"),
    a = cc._decorator,
    r = a.ccclass,
    s = a.property,
    c = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.panel = null;
    t.closeBtn = null;
    t.showPanelCloseBtn = null;
    t.bowlSprites = [];
    t.bowlSprite = null;
    t.controllerNode = null;
    t.controllerParent = null;
    t.mixNum = 0;
    t.mixShowPanel = null;
    t.mixShowAdSprite = null;
    t.shareBtn = null;
    t.getSkinBtn = null;
    t.noThanksBtn = null;
    t.noThanksBtn2 = null;
    t.switchNode = null;
    t.switchDot = null;
    t.skinSprite = null;
    t.skinFrames = [];
    t.skinIndex = -1;
    t.menuMixBtn = null;
    t.adSpriteFrame = null;
    t.changeAdSprites = [];
    return t;
  }

  n = t;

  t.prototype.onLoad = function () {
    n.Instance = this;
  };

  t.prototype.start = function () {
    -1 != this.getUnlockSkin() && SDK.Mgr.Inst.hasAds || (this.menuMixBtn.active = !1);
    if (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.tt) for (var e = 0; e < this.changeAdSprites.length; e++) {
      this.changeAdSprites[e].spriteFrame = this.adSpriteFrame;
    }
  };

  t.prototype.openPanel = function () {
    var e = this;

    if (-1 != this.getUnlockSkin() && SDK.Mgr.Inst.hasAds) {
      SDK.Mgr.Inst.event("ShowMixSkin");
      this.panel.active = !0;
      this.mixNum = 0;
      this.bowlSprite.spriteFrame = this.bowlSprites[this.mixNum];
      this.controllerParent.destroyAllChildren();
      cc.instantiate(this.controllerNode).setParent(this.controllerParent);
      this.closeBtn.active = !1;
      this.scheduleOnce(function () {
        e.closeBtn.active = !0;
      }, o["default"].Instance.closeDelayTime);
      SDK.Mgr.Inst.showInsert();
    }
  };

  t.prototype.closePanel = function () {
    this.panel.active = !1;
    this.controllerParent.destroyAllChildren();
    SDK.Mgr.Inst.showInsert();
  };

  t.prototype.getUnlockSkin = function () {
    var e = [0, 1, 2, 3, 4, 5, 6, 7, 8];
    e.sort(function () {
      return .5 - Math.random();
    });

    for (var t = 0; t < e.length; t++) {
      if (!o["default"].Instance.hasSkin(e[t])) return e[t];
    }

    return -1;
  };

  t.prototype.openFinishPanel = function () {
    SDK.Mgr.Inst.canShare() ? this.shareBtn.active = !0 : this.shareBtn.active = !1;

    if (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.tt) {
      this.shareBtn.active = !1;
      this.switchNode.active = !1;
      this.noThanksBtn2.active = !0;
      this.mixShowAdSprite.active = !0;
    } else {
      this.shareBtn.active = !1;
      this.switchNode.active = !1;
      this.noThanksBtn2.active = !1;
      this.mixShowAdSprite.active = !1;
    }

    this.freshFinishBtn();
    this.mixShowPanel.active = !0;
    this.skinIndex = this.getUnlockSkin();
    this.skinSprite.spriteFrame = this.skinFrames[this.skinIndex];
    SDK.Mgr.Inst.showInsert();
  };

  t.prototype.freshFinishBtn = function () {
    if (this.switchDot.active) {
      this.getSkinBtn.active = !0;
      this.noThanksBtn.active = !1;
    } else {
      this.getSkinBtn.active = !1;
      this.noThanksBtn.active = !0;
    }
  };

  t.prototype.switchBtnClick = function () {
    this.switchDot.active = !this.switchDot.active;
    this.freshFinishBtn();
  };

  t.prototype.addMixNum = function () {
    this.mixNum++;
    this.mixNum < 4 && (this.bowlSprite.spriteFrame = this.bowlSprites[this.mixNum]);
  };

  t.prototype.adBtnClick = function () {
    if (this.mixShowAdSprite.active) {
      var e = "MixGetSkin_Ad";
      SDK.Mgr.Inst.event(e + "Click");

      var t = this,
          n = function n(o) {
        if (o == SDK.Define.AdsCode.finish) {
          SDK.Mgr.Inst.event(e + "Success");
          t.realGetSkin();
          t.controllerParent.destroyAllChildren();
        } else if (o == SDK.Define.AdsCode.cancel) {
          SDK.Mgr.Inst.event(e + "Cancel");
          i["default"].Instance.openPanel(n);
        } else {
          SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
          SDK.Mgr.Inst.event(e + "NoAd");
        }
      };

      SDK.Mgr.Inst.showVideo(n);
    } else {
      this.realGetSkin();
      this.controllerParent.destroyAllChildren();
    }
  };

  t.prototype.cancelBtnClick = function () {
    this.mixShowPanel.active = !1;
  };

  t.prototype.shareBtnClick = function () {
    var e = this;
    this.shareBtn.active = !1;
    SDK.Mgr.Inst.event("shareClick");
    SDK.Mgr.Inst.share(function (t) {
      e.shareBtn.active = !0;

      if (t == SDK.Define.ShareCode.success) {
        SDK.Mgr.Inst.event("shareSuccess");
        e.shareBtn.active = !1;
        e.realGetSkin();
        e.scheduleOnce(function () {
          SDK.ToastMgr.Inst.showToast("发布成功，获得武器");
        }, .5);
      } else if (t == SDK.Define.ShareCode.cancel || t == SDK.Define.ShareCode.fail) {
        SDK.Mgr.Inst.event("shareCancel");
        e.scheduleOnce(function () {
          SDK.ToastMgr.Inst.showToast(t == SDK.Define.ShareCode.cancel ? "视频发布取消" : "视频录制中，稍后再试吧");
        }, .5);
      } else if (t == SDK.Define.ShareCode.tooShort) {
        SDK.Mgr.Inst.event("shareTooShort");
        e.scheduleOnce(function () {
          SDK.ToastMgr.Inst.showToast("视频录制中，稍后再试吧");
        }, .5);
      } else if (t == SDK.Define.ShareCode.pathNull) {
        SDK.Mgr.Inst.event("shareNullPath");
        e.scheduleOnce(function () {
          SDK.ToastMgr.Inst.showToast("视频录制中，稍后再试吧");
        }, .5);
      }
    });
  };

  t.prototype.realGetSkin = function () {
    this.mixShowPanel.active = !1;
    o["default"].Instance.setSkin(this.skinIndex, !0);
    o["default"].Instance.curSkinNum = this.skinIndex;
    SDK.ToastMgr.Inst.showToast("获得武器");
    -1 == this.getUnlockSkin() && (this.menuMixBtn.active = !1);
  };

  t.prototype.mixBtnClick = function () {
    if (this.mixNum < 3) SDK.ToastMgr.Inst.showToast("至少添加3种属性");else {
      var e = "MixEnd_Ad";
      SDK.Mgr.Inst.event(e + "Click");

      var t = this,
          n = function n(o) {
        if (o == SDK.Define.AdsCode.finish) {
          SDK.Mgr.Inst.event(e + "Success");
          t.openFinishPanel();
          t.panel.active = !1;
          t.controllerParent.destroyAllChildren();
        } else if (o == SDK.Define.AdsCode.cancel) {
          SDK.Mgr.Inst.event(e + "Cancel");
          i["default"].Instance.openPanel(n);
        } else {
          SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
          SDK.Mgr.Inst.event(e + "NoAd");
        }
      };

      SDK.Mgr.Inst.showVideo(n);
    }
  };

  var n;
  t.Instance = null;
  t.showMix = !1;

  __decorate([s(cc.Node)], t.prototype, "panel", void 0);

  __decorate([s(cc.Node)], t.prototype, "closeBtn", void 0);

  __decorate([s(cc.Node)], t.prototype, "showPanelCloseBtn", void 0);

  __decorate([s([cc.SpriteFrame])], t.prototype, "bowlSprites", void 0);

  __decorate([s(cc.Sprite)], t.prototype, "bowlSprite", void 0);

  __decorate([s(cc.Prefab)], t.prototype, "controllerNode", void 0);

  __decorate([s(cc.Node)], t.prototype, "controllerParent", void 0);

  __decorate([s(cc.Node)], t.prototype, "mixShowPanel", void 0);

  __decorate([s(cc.Node)], t.prototype, "mixShowAdSprite", void 0);

  __decorate([s(cc.Node)], t.prototype, "shareBtn", void 0);

  __decorate([s(cc.Node)], t.prototype, "getSkinBtn", void 0);

  __decorate([s(cc.Node)], t.prototype, "noThanksBtn", void 0);

  __decorate([s(cc.Node)], t.prototype, "noThanksBtn2", void 0);

  __decorate([s(cc.Node)], t.prototype, "switchNode", void 0);

  __decorate([s(cc.Node)], t.prototype, "switchDot", void 0);

  __decorate([s(cc.Sprite)], t.prototype, "skinSprite", void 0);

  __decorate([s([cc.SpriteFrame])], t.prototype, "skinFrames", void 0);

  __decorate([s(cc.Node)], t.prototype, "menuMixBtn", void 0);

  __decorate([s(cc.SpriteFrame)], t.prototype, "adSpriteFrame", void 0);

  __decorate([s([cc.Sprite])], t.prototype, "changeAdSprites", void 0);

  return n = __decorate([r], t);
}(cc.Component);

n["default"] = c;

cc._RF.pop();